<?php
//用户管理
namespace Admin\Controller;
use Think\Controller;
use Mcit\Page;

class MemberController extends BaseController {
    
    public function index(){
        if(!empty($_GET['card_number'])){
            $map['card_number'] = array('like','%'.I('card_number').'%');
        }
        //分页
        $count = M("member")->where("1")->order("id")->count();
        vendor('Mcit.Sys.Page');
        $Page = new Page($count, 20);
        $pageView = $Page->show();
        $this->assign('pageView', $pageView); //发送分页
        $nowPage = isset($_GET['page']) ? $_GET['page'] : 1;
        $this->member = M("member")->where($map)->page($nowPage . ',' . $Page->listRows)->select();
        //分页结束
		$this->display();
	}
    //用户详情页
    public function detail(){
        if(IS_GET){
            $this->member = M("member")->where("id='".I('id')."'")->find();
        }
        $this->display();
    }
    //添加用户处理页
    public function addUser(){
        if(IS_POST){
            $data = $_POST;
            $data['create_time'] = date('Y-m-d',time());
            $result = M("member")->data($data)->add();
            if($result >0){
                $this->redirect("Member/index");
            }else{
                $this->error("添加失败，请重试！");
            }
        }
        $this->display();
    }
    //编辑用户信息页
    public function editUser(){
        if(IS_GET){
            $this->member = M("member")->where("id='".I('id')."'")->find();
        }
        if(IS_POST){

        }
        $this->display();
    }
    //删除用户信息页
    public function delUser(){
        if(IS_AJAX){
            $map['id'] = I('id');
        $result = M('member')->where($map)->delete();
        if($result){
            $return['state'] = 100;
            $return['msg']   = "删除账号成功";
        }else{
            $return['state'] = 200;
            $return['msg']   = "删除失败";
        }
        echo json_encode($return);
        exit;
        }
    }

}